package com.zswl.decorate.base;

import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.zswl.decorate.R;
import com.zswl.decorate.js.WebJs;
import com.zswl.decorate.widget.MyWebView;

import butterknife.BindView;

public abstract class BaseWebViewActivity extends BackActivity {
    @BindView(R.id.wv)
    protected MyWebView myWebView;
    @BindView(R.id.tv_action_bar_title)
    TextView tvTitle;

    @Override
    protected void init() {
        if (getWebJs() != null) {
            myWebView.addJavascriptInterface(getWebJs(), "android");
        }
        myWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(getUrl());
                return true;
            }
        });
        myWebView.loadUrl(getUrl());

        tvTitle.setText(getActionBarTitle());

    }

    /**
     * 获取标题
     *
     * @return
     */
    public abstract String getActionBarTitle();


    /**
     * 获取加载url
     *
     * @return
     */
    public abstract String getUrl();

    /**
     * 获取js
     *
     * @return
     */
    public abstract WebJs getWebJs();


}
